#include "udpsocket.hpp"
using namespace std;

#define CHECK_RET(r) if((r) == false){return -1;}
int main(int argc,char *argv[]){
    if(argc!=3){
        cout<<"usage:./udp_srv 127.0.0.1 9000\n";
        return -1;
    }
    UdpSocket us;
    //创建套接字
    CHECK_RET(us.Socket());
    //绑定地址信息(不推荐)
    while(1){
    string buf;
    cout<<"client say:";
    fflush(stdout);
    cin>>buf;
    //发送数据
    CHECK_RET(us.Send(buf,argv[1],stoi(argv[2])));
    //接收数据
    buf.clear();
    CHECK_RET(us.Recv(&buf));
    cout<<"server say:"<<buf<<endl;
    }
    //关闭套接字
    us.Close();
    return 0;
}